<template>
	<el-dialog
	  title="领取"
	  :visible.sync="visible"
	  :before-close="close"
	  :close-on-click-modal="false"
	  width="70%">
    注：此操作会记录在《样品接收与分发记录》，并确认以下说明
	  <el-row>
	    <el-col :span="24">
        <el-card>
          <el-form>
            <el-form-item
              v-for="(item, index) in dataList"
              :key="index"
              :prop="'dataList.' + index + 'getQuantity'">
                确定接收 {{item.dispenseUserName}} 分发的样品<span class="font-highlight">【{{item.checkTypeName}}】{{item.productName}}（批号：{{item.batchNum}}，规格：<span v-html="item.productSpec"></span><span v-if="item.productPackSpec != null">，包装规格：{{item.productPackSpec}}</span>）
                {{item.groupGetQuantity + item.groupGetUnitName}}</span>
            </el-form-item>
          </el-form>
        </el-card>
      </el-col>
	  </el-row>

	  <span slot="footer" class="dialog-footer">
	    <el-button @click="close">取 消</el-button>
	    <el-button type="primary" class="pan-btn primary-btn" :loading="submiting" @click="submit()">确 定</el-button>
  	</span>
	</el-dialog>
</template>

<script>
  import { groupGet } from '@/api/check'
	import { CODE_OK } from '@/common/js/config'
  import { isBlank } from '@/common/js/utils'
	export default {
		data() {
			return {
				visible: false,
        submiting: false,
        dataList: []
			}
		},
		props: ["childDataForm"],
		created() {
			if (!isBlank(this.childDataForm)) {
				this.dataList = this.childDataForm
        this.visible = true
			}
		},
		methods: {
			close(val) {
				this.$emit('close')
				if (val == 'submit') {
				  this.$emit('refreshData')
				}
				this.visible = false
			},
			submit() {
        this.submiting = true
        const data = this.dataList.map(item => {
          let it = {
            checkId: item.checkId,
            groupId: item.inspectionGroupId
          }
          return it
        })
        groupGet(data).then(res => {
          if (res.code === CODE_OK) {
            this.$message({
              message: '提交成功',
              type: 'success',
              duration: 1500
            })
            this.close("submit")
          }else{
            this.submiting = false
            this.$message.error(res.msg)
          }
        })
			}
    }
	}
</script>

<style>
</style>
